package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Product;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class ProductDao {

	private DBHelp<Product> db = new DBHelp<Product>();

	public List<Product> findAlls() {
		String sql = "select `name`,price,isONload,bianhao from t_product";
		return db.executeQueryForList(sql, new GoodRowMapper());

	}

	public void add(String name, float price, boolean isONload, String bianhao) {

		String sql = "insert into t_product(`name`,price,isONload,bianhao) values(?,?,?,?) ";
		db.executeSQL(sql, name, price, isONload, bianhao);
	}

	private class GoodRowMapper implements RowMapper<Product> {

		public Product mapperRow(ResultSet rs) throws SQLException {
			Product product = new Product();
			product.setBianhao(rs.getString("bianhao"));
			product.setName(rs.getString("name"));
			product.setIsONload(rs.getBoolean("isONload"));
			product.setPrice(rs.getFloat("price"));

			return product;
		}
	}
}
